package com.game.majiang.algorithm;

import com.game.majiang.config.LogManager;

import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
public class PaperCard implements Cloneable{

	private int id;
	private int type;// 1黑桃 2红桃 3梅花  4方块
	private int num;//对应牌 1-13    A-k  14 小王 15 大王 
	private int point;//点数  
	private boolean laizi = false; 
	private int chexuanValue;//扯旋单张比大小用 牌面大小顺序为：红Q＞红2＞红8＞红4＞（黑10＝黑4＝黑6）＞（黑J＝红10＝红6＝红7）＞（黑5＝黑7＝黑8＝黑9＝红桃3＝大王

	public PaperCard initCard(int id, int type, int num) {
		this.id = id;
		this.type = type;
		this.num = num;
		if (num > 10) {
			this.point = 10;
		} else {
			this.point = num;
		}
		return this;
	}
	public PaperCard initChexuanCard(int id, int type, int num) {
		this.id = id;
		this.type = type;
		this.num = num;
		this.point = num % 10;
		if(this.num == 15) {
			this.point = 6;
		}
		if(this.num == 12 && this.type % 2 == 0) {
			this.chexuanValue = 99;
		} else if(this.num == 2 && this.type % 2 == 0) {
			this.chexuanValue = 98;
		} else if(this.num == 8 && this.type % 2 == 0) {
			this.chexuanValue = 97;
		} else if(this.num == 4 && this.type % 2 == 0) {
			this.chexuanValue = 96;
		}else if((this.num == 4 || this.num == 6 || this.num == 10 ) && this.type % 2 == 1) {
			this.chexuanValue = 95;
		}else if((this.num == 11 && this.type % 2 == 1) || ((this.num == 6 || this.num == 7 || this.num == 10) && this.type % 2 == 0)) {
			this.chexuanValue = 94;
		} else if(((this.num == 5 ||this.num == 7 || this.num == 8|| this.num == 9) && this.type % 2 == 1) || (this.num == 3 && this.type % 2 == 2) || this.num == 15) {
			this.chexuanValue = 93;
		}
		return this;
	}
	public void numToPoint() {
		if (this.num > 10) {
			this.point = 10;
		} else {
			this.point = this.num;
		}
	}


	@Override
	public PaperCard clone() {

		PaperCard pc = null;
		try {
			pc = (PaperCard) super.clone();
		} catch (Exception e) {
			LogManager.getInstance().Error("克隆PaperCard失败");
		}
		return pc;
	}


	@Override
	public String toString() {
		StringBuffer str = new StringBuffer();
		if (this.num < 53) {
			switch (this.type) {
			case 1:
				str.append("黑桃");
				break;
			case 2:
				str.append("红桃");
				break;
			case 3:
				str.append("梅花");
				break;
			case 4:
				str.append("方块");
				break;
			default:
				break;
			}
		}

		switch (this.num) {
		case 1:
			str.append("A");
			break;
		case 11:
			str.append("J");
			break;
		case 12:
			str.append("Q");
			break;
		case 13:
			str.append("K");
			break;
		case 14:
			str.append("小王");
			break;
		case 15:
			str.append("大王");
			break;
		default:
			str.append(this.num);
			break;
		}
		str.append(this.laizi ? "-癞子" : "");
		str.append("-id:"+this.id);
		return str.toString();
	}



}
